﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Host.Helper;
using Host.Models;
using iTextSharp.text;
using iTextSharp.text.pdf;
using Font = iTextSharp.text.Font;

namespace Host.Controllers
{
    public class RegController : Controller
    {
        //
        // GET: /Reg/

        public ActionResult Revised()
        {
            return View();
        }

        [HttpPost]
        public Stream Revised(RegModel model, string returnUrl)
        {
            
            if (ModelState.IsValid)
            {
                {
                    using (var doc = new Document())
                    {
                        PdfWriter writer = PdfWriter.GetInstance(doc, Response.OutputStream);
                        doc.Open();
                        doc.AddTitle("Regulations 28 Report");
                        doc.AddHeader("Regulations 28 Report", "Report");

                        PdfPTable table = new PdfPTable(4);
                        table.WidthPercentage = 100f;
                        
                        //table.AddCell("Cell 1");
                        //PdfPCell cell = new PdfPCell(new Phrase("Cell 2", new  Font( new iTextSharp.text.Font{ Color = BaseColor.BLACK, Size = 10})));
                        //cell.BackgroundColor = new iTextSharp.text.BaseColor(0, 150, 0);
                        Paragraph mainHeader = new Paragraph("Regulation 28 Revised Report" + " placeholder for client name")
                                                   {
                                                       Font = new Font(Font.FontFamily.HELVETICA, 10f), Alignment = 20
                                                   };


                        doc.Add(mainHeader);

                        PdfPCell[] firstRow = new PdfPCell[] { new PdfPCell
                                                                   {
                                                                        Phrase = new Phrase("Asset Class/Instrument"){ Font = new Font(Font.FontFamily.HELVETICA, 10f)}, 
                                                                        Border = 0,
                                                                        BackgroundColor = new BaseColor(StyleHelper.Blue )
                                                                   }, 
                                                                new PdfPCell
                                                                    {
                                                                        Phrase = new Phrase("Old Regulation 28"), Border = 0,
                                                                        BackgroundColor = new BaseColor(StyleHelper.Blue )
                                                                    },
                                                                new PdfPCell
                                                                    {
                                                                        Phrase = new Phrase(" New Regulation 28"), Border = 0,
                                                                        BackgroundColor = new BaseColor(StyleHelper.Blue )
                                                                    },
                                                                new PdfPCell
                                                                    {
                                                                        Phrase = new Phrase("Input Values"), Border = 0,
                                                                        BackgroundColor = new BaseColor(StyleHelper.Blue )
                                                                    } 
                                                        }; 

                        PdfPRow row = new PdfPRow(firstRow);
                        
                        table.Rows.Add(row);
                        doc.Add(table);


                        var header = new Paragraph("Regulations 28 Report") {Alignment = 10};
                        doc.Add(header);

                        var p = new Paragraph( "Commodities Kruger Rands:   " + model.CommKruger.ToString())
                                          {Alignment = 1};
                        doc.Add(p);
                        
                        doc.Close();
                    } 
                }
                
            }
            return Response.OutputStream;
        }

    }
}
